home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / btime.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  3KB  |  94 lines

  1.  
  2. #include "driver.h"
  3.  
  4.  
  5. #define BASE  0xb000
  6.  
  7.  
  8. static int protection_command;
  9. static int protection_status = 0;
  10. static int protection_value;
  11. static int protection_ret = 0;
  12.  
  13.  
  14. READ_HANDLER( mmonkey_protection_r )
  15. {
  16.     unsigned char *RAM = memory_region(REGION_CPU1);
  17.  
  18.     int ret = 0;
  19.  
  20.     if      (offset == 0x0000)                      ret = protection_status;
  21.     else if (offset == 0x0e00)                      ret = protection_ret;
  22.     else if (offset >= 0x0d00 && offset <= 0x0d02)  ret = RAM[BASE+offset];  /* addition result */
  23.     else logerror("Unknown protection read.  PC=%04X  Offset=%04X\n", cpu_get_pc(), offset);
  24.  
  25.     return ret;
  26. }
  27.  
  28.  
  29.  
  30. WRITE_HANDLER( mmonkey_protection_w )
  31. {
  32.     unsigned char *RAM = memory_region(REGION_CPU1);
  33.  
  34.  
  35.     if (offset == 0)
  36.     {
  37.         /* protection trigger */
  38.         if (data == 0)
  39.         {
  40.             int i,s1,s2,r;
  41.  
  42.             switch (protection_command)
  43.             {
  44.             case 0:    /* score addition */
  45.  
  46.                 s1 = (    1 * (RAM[BASE+0x0d00] & 0x0f)) + (    10 * (RAM[BASE+0x0d00] >> 4)) +
  47.                      (  100 * (RAM[BASE+0x0d01] & 0x0f)) + (  1000 * (RAM[BASE+0x0d01] >> 4)) +
  48.                      (10000 * (RAM[BASE+0x0d02] & 0x0f)) + (100000 * (RAM[BASE+0x0d02] >> 4));
  49.  
  50.                 s2 = (    1 * (RAM[BASE+0x0d03] & 0x0f)) + (    10 * (RAM[BASE+0x0d03] >> 4)) +
  51.                      (  100 * (RAM[BASE+0x0d04] & 0x0f)) + (  1000 * (RAM[BASE+0x0d04] >> 4)) +
  52.                      (10000 * (RAM[BASE+0x0d05] & 0x0f)) + (100000 * (RAM[BASE+0x0d05] >> 4));
  53.  
  54.                 r = s1 + s2;
  55.  
  56.                 RAM[BASE+0x0d00]  =  (r % 10);        r /= 10;
  57.                 RAM[BASE+0x0d00] |= ((r % 10) << 4);  r /= 10;
  58.                 RAM[BASE+0x0d01]  =  (r % 10);        r /= 10;
  59.                 RAM[BASE+0x0d01] |= ((r % 10) << 4);  r /= 10;
  60.                 RAM[BASE+0x0d02]  =  (r % 10);        r /= 10;
  61.                 RAM[BASE+0x0d02] |= ((r % 10) << 4);
  62.  
  63.                 break;
  64.  
  65.             case 1:    /* decryption */
  66.  
  67.                 /* Compute return value by searching the decryption table. */
  68.                 /* During the search the status should be 2, but we're done */
  69.                 /* instanteniously in emulation time */
  70.                 for (i = 0; i < 0x100; i++)
  71.                 {
  72.                     if (RAM[BASE+0x0f00+i] == protection_value)
  73.                     {
  74.                         protection_ret = i;
  75.                         break;
  76.                     }
  77.                 }
  78.                 break;
  79.  
  80.             default:
  81.                 logerror("Unemulated protection command=%02X.  PC=%04X\n", protection_command, cpu_get_pc());
  82.                 break;
  83.             }
  84.  
  85.             protection_status = 0;
  86.         }
  87.     }
  88.     else if (offset == 0x0c00)                      protection_command = data;
  89.     else if (offset == 0x0e00)                      protection_value = data;
  90.     else if (offset >= 0x0f00)                      RAM[BASE+offset] = data;   /* decrypt table */
  91.     else if (offset >= 0x0d00 && offset <= 0x0d05)  RAM[BASE+offset] = data;   /* source table */
  92.     else logerror("Unknown protection write=%02X.  PC=%04X  Offset=%04X\n", data, cpu_get_pc(), offset);
  93. }
  94.